package com.greyu.ysj.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.greyu.ysj.entity.CbtMinerRate;
import com.greyu.ysj.entity.CbtMinerRateExample;
import com.greyu.ysj.entity.CbtMinerRatio;
import com.greyu.ysj.entity.CbtMinerRatioExample;
import com.greyu.ysj.mapper.CbtMinerRatioMapper;
import com.greyu.ysj.service.CbtMinerRatioService;
@Service
public class CbtMinerRatioServiceImpl implements CbtMinerRatioService {
	@Autowired
	private CbtMinerRatioMapper cbtMinerRatioMapper;
	@Override
	public int getUserLevelByAsset(double asset) {
		// TODO Auto-generated method stub
		List<CbtMinerRatio> list =  this.cbtMinerRatioMapper.selectByExample(new CbtMinerRatioExample());
		for (CbtMinerRatio cbtMinerRatio : list) {
			if (asset >= cbtMinerRatio.getMinAsset() 
			   && asset < cbtMinerRatio.getMaxAsset()) {
				return cbtMinerRatio.getLeve();
			}
		}
		return 0;
	}

	@Override
	public double getRatioByLevel(int level) {
		// TODO Auto-generated method stub
		CbtMinerRatioExample cbtMinerRatioExample = new CbtMinerRatioExample();
		CbtMinerRatioExample.Criteria criteria=cbtMinerRatioExample.createCriteria();
		criteria.andLeveEqualTo(level);
		List<CbtMinerRatio> list=this.cbtMinerRatioMapper.selectByExample(cbtMinerRatioExample);
		if (null !=list && list.size() >=0) {
			return list.get(0).getRatio();
		}
		return 0.001;
	}

	@Override
	public CbtMinerRatio getMinerRatioByLevel(int level) {
		// TODO Auto-generated method stub
		CbtMinerRatioExample cbtMinerRatioExample = new CbtMinerRatioExample();
		CbtMinerRatioExample.Criteria criteria=cbtMinerRatioExample.createCriteria();
		criteria.andLeveEqualTo(level);
		List<CbtMinerRatio> list=this.cbtMinerRatioMapper.selectByExample(cbtMinerRatioExample);
		if (null !=list && list.size() >=0) {
			return list.get(0);
		}
		return null;
	}

}
